home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: What to do when feof() is NOT feof()
- Date: 19 Feb 96 22:28:56 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.824768936@rscernix>
- References: <824554814snz@metsys.demon.co.uk> <4g4vpp$52f@spectator.cris.com> <danpop.824614833@rscernix> <4g7rsj$fnf@spectator.cris.com> <4ga195$nsq@lodur.easysoft.com>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4ga195$nsq@lodur.easysoft.com> nick@news.easysoft.com (Nick Gorham) writes:
-
- >thinks he asked, but that is not Dan's fault. As the above _Expert_
- >knows "rt" opens a text file on MSDOS but I don't see any mention of
- >it under several OS's that have 'C' compilors.
-
- For the simple reason that there is no "rt" mode in the C language.
- However, "rt" is guaranteed to work everywhere and open the file in text
- mode. Why? Because the standard says that 'r' followed by any amount
- of _meaningless_ gibberish is the same as "r", which means: open in text
- mode for reading.
-
- Then, why is "rt" documented by many MSDOS C implementations? Because
- those implementations add a (brain-dead) "feature": they allow the
- programmer to alter the behaviour of the stdio library so that "r"
- actually means "rb". Needless to say, once you do this, the library is
- not standard conforming any longer. If the programmer decided to use this
- "feature", he needs a way to specify that he wants to open a file in text
- mode, and this way is "rt". Now, "rt" is no longer equivalent to "r" as
- required by the standard, but this is irrelevant, because the library isn't
- standard conforming, anyway.
-
- The net result is that although nobody (in his right mind) changes the
- default behaviour of the stdio library, people become confused WRT to
- the actual meaning of "r" and use "rt", just to be sure.
-
- Needless to say, the above discussion applies to "wt" as well.
-
- The story isn't over, however :-) If "rt" is OK and portable anywhere,
- "rt+" is a different case: it is equivalent to "r+" on MSDOS, but on
- any other platform it is equivalent to "r", because the meaningless 't'
- _and_ all the characters following it are discarded. So, the correct
- spelling, if portability is a concern, is "r+t". This remark also
- applies to "r+b" vs "rb+": while the two versions are equivalent on any
- ANSI-conformant library, "r+b" will also work on pre-ANSI libraries
- (which don't "understand" the 'b'), "rb+" will be interpreted as "r" by
- such a library. So, "r+b" is a little bit more portable than "rb+",
- which is a good reason to prefer it.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-